<template>
    <el-container>
        <el-header class="head">
            <p class="head-p">哈哈车位管理系统</p>
            <p class="p-width">
                <img src="../../../assets/h1.jpeg" alt="" class="head-img" />
                <span class="span"
                    >欢迎您 <i> {{ token }}</i>
                </span>
                <button class="button" @click="exit">退出</button>
            </p>
        </el-header>
        <el-container class="container">
            <el-aside width="200px">
                <el-menu
                    default-active="2"
                    class="el-menu-vertical-demo"
                    @open="handleOpen"
                    @close="handleClose"
                    :router="true"
                >
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>车位管理</span>
                        </template>
                        <el-menu-item index="/Lessors/LessorsList"
                            >我的车位</el-menu-item
                        >
                        <el-menu-item index="/Lessors/AddLessors"
                            >发布车位</el-menu-item
                        >
                        <!-- <el-menu-item index="/Lessors/UpdateLessors"
                            >修改车位</el-menu-item
                        > -->
                    </el-submenu>
                    <el-submenu index="2">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>订单管理</span>
                        </template>
                        <el-menu-item index="/Lessors/NewOrders"
                            >查看订单</el-menu-item
                        >
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers(
    "lessors"
);
import apis from "../../../http/apis/apis.js";
import axios from '../../../http/axios.js'
export default {
    data() {
        return {};
    },
    mounted() {
        this.tokenGet()
        // this.getToken();
        
        this.getTokenID();
    },
    computed: {
        ...mapState(["token"]),
    },
    methods: {
        ...mapActions(["getTokenID"]),
        ...mapMutations(['tokenGet']),
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },

        // 退出登录
        exit() {
            axios({
                    url:'/logs/createLogs',
                    method:'post',
                    data:{
                        name:this.token,
                        operation:'退出登录',
                        result:'成功'
                    }
                    })
            this.$confirm("退出登录, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    setTimeout(() => {
                        localStorage.clear(this.token);
                        this.$router.push({ path: "/login" });
                        this.$message({
                            type: "success",
                            message: "已退出登录!",
                        });
                    }, 1000);
                    
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消",
                    });
                });
                
        },
        
    },
};
</script>
<style>
html,
body {
    padding: 0px;
    margin: 0px;
}
.container {
    height: 100vh;
}
.el-header {
    background-color: #3e4b58;
    color: #333;
    font-size: 17px;
    line-height: 60px;
    color: gainsboro;
}

.el-aside {
    background-color: #d3dce6;
    color: #333;
}

.el-main {
    background-color: #e9eef3;
    color: #333;
}

/* 头部 */
.head {
    display: flex;
}
.head-p {
    width: 67%;
    line-height: 60px;
    padding: 0px;
    margin: 0px;
}
.p-width {
    width: 30%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 105px;
    box-sizing: border-box;
}
.head-img {
    width: 50px;
    vertical-align: middle;
    border-radius: 50%;
}
.span {
    margin-left: 10px;
}
.button {
    width: 50px;
    height: 30px;
    margin-left: 30px;
    background-color: #3e4b58;
    outline: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
}
</style>